<?php
class M_baigiang extends CI_Model
{
    public $data;
    
	public function __construct()
	{
		parent::__construct();
		// Your own constructor code
	}
    public function select_id_khoahoc()
    {
        $this->db->select('id');
        $this->db->from('khoahoc');
        $this->db->where('khoahoc.id',$this->db->insert_id());
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
    public function get_insert($tb, $nd, $img, $video, $tailieu, $ngay, $idkhoahoc, $tuan)
    {     
        
        $data = array(
                'ten_bai'     => $tb,
                'noidung'     => $nd,
                'images'      => $img,
                'video'       => $video,
                'tailieu'     => $tailieu,
                'ngay'        => $ngay,
                'state'       => 1,
                'id_khoahoc'  => $idkhoahoc,
                'tuan'        => $tuan
            );            
            $result = $this->db->insert('baigiang', $data);
            if($result){
                return true;
            }else{
                return false;
            }
            $result->free_result();;
    }
        
    public function get_select()
    {     
        $this->db->select('*');
        $this->db->from('baigiang');
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
    
    function get_delete($id) 
    {
        if(!empty($id)){
            $this->db->where('id', $id);
            $result = $this->db->delete('baigiang');
            if($result){
                return true;
            }else{
                return false;
            }
        }
        return false;
    }
    public function get_update($id)
    {
        $data = array(
            'fullname'   =>$this->input->post('username'),
            'email'    =>$this->input->post('email'),
            'password'   =>sha1($this->input->post('password')),
            'state'   =>$this->input->post('state')
            ); 
        $this->db->where('id_user', $id);
        $this->db->update('login', $data);  
        return $result;
        $result->free_result();; 
    }
   
}
?>